package com.example.onlinemonitoring.comCenter;
import com.example.onlinemonitoring.Util.CRC16;
import com.example.onlinemonitoring.Util.CommPortManager;
import com.example.onlinemonitoring.Util.IEEE754Utils;
import com.example.onlinemonitoring.model.Appdevice;
import com.example.onlinemonitoring.model.Txpdsensor;
import org.springframework.context.annotation.Scope;
import com.example.onlinemonitoring.serviceImpl.TxpdsensorServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
@Service("txpd61850Com")
@Scope("prototype")
public class Txpd61850Com extends CommPortManager  {
    @Autowired
    private TxpdsensorServiceImpl txpdserviceimpl;
    @Override
    public void receiveData(String str) {
        setText("收到sanway请求：" + str + "\r\n");
        int startAddr = parseHex4(str.substring(0, 2));
        String flag = str.substring(6, 8);
        String s = "";
        Txpdsensor txpd = new Txpdsensor();
        txpd.setStationid(ad.getStationid());
        txpd.setDevicegroup(ad.getDevicegroup());
        txpd.setDeviceaddr(startAddr);
        if(flag.equals("34")){
            txpd.setPointaddr(9);
            txpd = txpdserviceimpl.getModel(txpd);
            if(txpd == null)
            txpd = new Txpdsensor();
            s += str.substring(0, 2);
            s += "0404";
            s += IEEE754Utils.singleToHexConvert(isnull(txpd.getLastdata()));
            s += CRC16.calcCrc16(s);
            Send(s);
            setText("SANWAY模块转发铁芯数据：" + s + "\r\n");
        }else if(flag.equals("36")){
            txpd.setPointaddr(10);
            txpd = txpdserviceimpl.getModel(txpd);
            if(txpd == null)
            txpd = new Txpdsensor();
            s += str.substring(0, 2);
            s += "0404";
            s += IEEE754Utils.singleToHexConvert(isnull(txpd.getLastdata()));
            s += CRC16.calcCrc16(s);
            Send(s);
            setText("SANWAY模块转发夹件数据：" + s + "\r\n");
        }
        // else if(flag.equals("32")){
        //     txpd.setPointaddr(1);
        //     txpd = txpdserviceimpl.getModel(txpd);
        //     if(txpd == null)
        //     txpd = new Txpdsensor();
        //     s += str.substring(0, 2);
        //     s += "0404";
        //     s += IEEE754Utils.singleToHexConvert(isnull(txpd.getLastdata()));
        //     s += CRC16.calcCrc16(s);
        //     Send(s);
        //     setText("SANWAY模块转发油温数据：" + s + "\r\n");
        // }
        // else if(flag.equals("30")){
        //     txpd.setPointaddr(2);
        //     txpd = txpdserviceimpl.getModel(txpd);
        //     if(txpd == null)
        //     txpd = new Txpdsensor();
        //     s += str.substring(0, 2);
        //     s += "0404";
        //     s += IEEE754Utils.singleToHexConvert(isnull(txpd.getLastdata()));
        //     s += CRC16.calcCrc16(s);
        //     Send(s);
        //     setText("SANWAY模块转发油位数据：" + s + "\r\n");
        // }
    }
}
